package edu.cityu.cs.hk.datastructures;
import java.util.Iterator;
/**
 * An interface for a graph.
 * @author Roberto Tamassia
 */
//begin#fragment Graph
public interface Graph {
  /** Return an iterator over the vertices of the graph */
  public Iterator vertices();
  /** Return an iterator over the edges of the graph */
  public Iterator edges();
  /** Replace the element a given position (vertex or edge) with a new
      element and return the old element */
  public Object replace(Position p, Object o)
    throws InvalidPositionException;
  /** Return an iterator over the edges incident on a vertex */
  public Iterator incidentEdges(Vertex v)
    throws InvalidPositionException;
  /** Return the endvertices of a vertex as an array of length 2 */
  public Vertex[] endVertices(Edge e)
    throws InvalidPositionException;
  /** Return the other endvertex of an incident edge */
  public Vertex opposite(Vertex v, Edge e)
    throws InvalidPositionException;
  /** Test whether two vertices are adjacent */
  public boolean areAdjacent(Vertex u, Vertex v)
    throws InvalidPositionException;
  /** Insert and return a new vertex with a given element */
  public Vertex insertVertex(Object o);
  /** Insert and return a new edge with a given element between two
      vertices */
  public Edge insertEdge(Vertex u, Vertex v, Object o)
    throws InvalidPositionException;
  /** Remove a vertex and all its incident edges and return the
      element stored at the removed vertex */
  public Object removeVertex(Vertex v)
    throws InvalidPositionException;
  /** Remove an edge and return its element */
  public Object removeEdge(Edge e)
    throws InvalidPositionException;
}
//end#fragment Graph

